package com.hk.huakangcompany.mapper;

import com.hk.huakangcompany.model.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: zhe
 * @Date: 2021/6/8 15:19
 * @Statement: 会员Mapper层接口
 */
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from user where email = #{email}")
    User findByEmail(String email);

    @Update("update user set password=#{password},gmt_modified=#{gmtModified} where id = #{id} ")
    int updatePassWord(User user);

    @Update("update user set state=#{state},gmt_modified=#{gmtModified} where id = #{id} ")
    int updateState(User user);

    @Override
    List<User> findAll(User user);

    @Override
    int count(User user);

    @Select("select * from user where id = #{id}")
    @Override
    User findById(Integer id);

    @Insert("insert into user" +
            "        value (" +
            "            null ,#{username},#{email},#{password},#{sex},#{birthday}," +
            "            #{hobby},#{phone},#{site},#{gmtCreate},#{gmtModified},#{state}" +
            "        )")
    @Override
    int save(User user);

    @Update("update user set " +
            "username=#{username},email=#{email},sex=#{sex},birthday=#{birthday}," +
            "hobby=#{hobby},phone=#{phone},site=#{site},gmt_modified=#{gmtModified}" +
            " where id = #{id}")
    @Override
    int update(User user);

    @Delete("delete from user where id = #{id} ")
    @Override
    int delete(Integer id);
}
